﻿using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace RaptorEngine.Components.Drawable
{
	public class DrawableModel : Drawable3DComponent
	{
        public DrawableModel(Entity entity,Model model, BasicEffect effect)
            :base(entity, model, effect)
        {
          
        }

		internal override void Draw(Matrix parentWorld, Matrix view, Matrix projection)
        {
	        Matrix world = parentWorld * worldMatrix;         
      
            foreach (ModelMesh mesh in _model.Meshes)
            {
                foreach (BasicEffect effect in mesh.Effects)
                {
					//part.Effect.Parameters["WorldViewProj"].SetValue(worldViewProj);
					//effect.LightingEnabled = Effect.LightingEnabled;
					effect.EnableDefaultLighting();
                    effect.DirectionalLight0.DiffuseColor = Effect.DirectionalLight0.DiffuseColor;
                    effect.DirectionalLight0.Direction = Effect.DirectionalLight0.Direction;
                    effect.DirectionalLight0.SpecularColor = Effect.DirectionalLight0.SpecularColor;

                    effect.DirectionalLight1.DiffuseColor = Effect.DirectionalLight1.DiffuseColor;
                    effect.DirectionalLight1.Direction = Effect.DirectionalLight1.Direction;
                    effect.DirectionalLight1.SpecularColor = Effect.DirectionalLight1.SpecularColor;

					effect.World = mesh.ParentBone.Transform * world;
					effect.Projection = projection;
					effect.View = view;
                    //part.Effect = _effect;
                    //part.Effect.Techniques[0].Passes[0].Apply();
/*
                    _effect = (BasicEffect)part.Effect;
                    _effect.EnableDefaultLighting();
                    _effect.World = parentWorld;
                    _effect.Projection = projection;
                    _effect.View = view;
                    part.Effect = _effect;
                    part.Effect.Techniques[0].Passes[0].Apply();
*/
                }
                
                mesh.Draw();
            }
        }
	}
}
